import vue from 'vue'
import App from './App.vue'

import Elementui from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import router from './router/indext.js'
import store from '../store'
import http from 'axios'
import '../api/mock.js'

// const routerPush = router.prototype.push
// router.prototype.push = function push(location) {
//   return routerPush.call(this, location).catch(error=> error)
// }

vue.config.productionTip = false
vue.use(Elementui)
vue.prototype.$http = http
// vue.prototype.$message = Message
router.beforeEach((to,from,next) => {
  console.log("触发路由守卫");
store.commit('getToken')

  const token =store.state.use.token
  console.log(token);
  if(!token && to.name !=='login'){
    next({name:'login'})
  }else if(token&&to.name==='login'){

    next({name:'login'})

  }else{
    next()
  }


})
new vue({
  store,
  router: router,
  render: h => h(App),
  created(){
         store.commit('addMenu', router)

  }
}).$mount('#app')
